package cn.lzd.mr.case10;


import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;

/**
 * Created by lzd on 2019/7/16.
 */

public class Bean implements WritableComparable<Bean> {

    public Bean() {
    }

    private String key;
    private String value;

    public Bean(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    @Override
    public int compareTo(Bean o) {
        HashSet<String> sets = new HashSet<>();
        String[] arr1 = this.value.split(",", -1);
        String[] arr2 = o.getValue().split(",", -1);
        sets.addAll(Arrays.asList(arr1));
        sets.addAll(Arrays.asList(arr2));

        if (sets.size() < (arr1.length + arr2.length)) {
            return 0;
        }
        return 0;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.getKey());
        dataOutput.writeUTF(this.getValue());
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.key = dataInput.readUTF();
        this.value = dataInput.readUTF();
    }
}
